package weibo4android.androidexamples;



import cn.com.karl.logic.AsyncBitmapLoader;
import cn.com.karl.logic.MainService;
import cn.com.karl.logic.Task;
import cn.com.karl.net.NetUtil;
import weibo4android.User;
import weibo4android.androidexamples.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

public class MyContactActivity extends Activity implements IWeiboActivity {
	
	private ImageView mycontact_iamgeIcon;
	private TextView mycontact_textName;
	private Button mycontact_editBtn;
	private TextView mycontact_address;
	private TextView mycontact_loginName;
	private TextView mycontact_item_attention;
	private TextView mycontact_item_weibo;
	private TextView mycontact_item_interest;
	private TextView mycontact_item_topic;
	private TextView head_userName;
	private  ProgressDialog p;
	private Button head_new;
	private Button head_refresh;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	    setContentView(R.layout.mycontact);
		
	    head_new=(Button) this.findViewById(R.id.head_new);
		head_new.setVisibility(View.GONE);
		
		head_refresh=(Button) this.findViewById(R.id.head_refresh);
		head_refresh.setVisibility(View.GONE);
		
		head_userName=(TextView) this.findViewById(R.id.head_userName);
		head_userName.setText("个人资料");
	    
	    MainService.addActivity(this);
	    MainService.newTask(new Task(Task.MYCONTACT,null));
       p=ProgressDialog.show(this, "", "正在加载，请稍候  . . .  ");
	    
	    mycontact_textName=(TextView) findViewById(R.id.mycontact_textName);
	    mycontact_iamgeIcon=(ImageView) this.findViewById(R.id.mycontact_iamgeIcon);
	    mycontact_editBtn=(Button) this.findViewById(R.id.mycontact_editBtn);
	    mycontact_address=(TextView) this.findViewById(R.id.mycontact_address);
	    mycontact_loginName=(TextView) this.findViewById(R.id.mycontact_loginName); 
	    mycontact_item_attention=(TextView) this.findViewById(R.id.mycontact_item_attention);
	    mycontact_item_weibo=(TextView) this.findViewById(R.id.mycontact_item_weibo);
	    mycontact_item_interest=(TextView) this.findViewById(R.id.mycontact_item_interest);
	    mycontact_item_topic=(TextView) this.findViewById(R.id.mycontact_item_topic);
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		MainService.removeActivity(this);
		super.onDestroy();
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		
		if(keyCode==KeyEvent.KEYCODE_BACK){
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("你确定退出吗？")
			       .setCancelable(false)
			       .setPositiveButton("确定", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			                MyContactActivity.this.finish();
			                //停止服务
			                Intent it=new Intent(MyContactActivity.this,MainService.class);
			                MyContactActivity.this.stopService(it);
			               android.os.Process.killProcess(android.os.Process.myPid());
			               android.os.Process.killProcess(android.os.Process.myTid());
			               android.os.Process.killProcess(android.os.Process.myUid());
			           }
			       })
			       .setNegativeButton("返回", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			                dialog.cancel();
			           }
			       });
			AlertDialog alert = builder.create();
			alert.show();
			return true;
		}
		
		return super.onKeyDown(keyCode, event);
	}
	@Override
	public void init() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void refresh(Object... params) {
		// TODO Auto-generated method stub
		User user=(User) params[0];
		p.dismiss();
		mycontact_textName.setText("微博昵称:"+user.getScreenName());
		//异步加载图片
		new AsyncBitmapLoader().execute(mycontact_iamgeIcon,user.getProfileImageURL().toString());
		//mycontact_iamgeIcon.setBackgroundDrawable(NetUtil.getNetImage(user.getProfileImageURL()));
		mycontact_address.setText(user.getLocation());
		mycontact_loginName.setText(user.getDescription());
		mycontact_item_attention.setText(String.valueOf(user.getFriendsCount()));
		mycontact_item_weibo.setText(String.valueOf(user.getStatusesCount()));
		mycontact_item_interest.setText(String.valueOf(user.getFollowersCount()));
		mycontact_item_topic.setText(String.valueOf(user.getFavouritesCount()));
	}
	
}
